package com.fingard.dsp.bank.reqrespobj.frgcurrsinglecheck;

import com.fingard.dsp.bank.reqrespobj.ReqRespHeader;
import com.fingard.dsp.bank.reqrespobj.RetAtsBase;
import com.fingard.dsp.bank.reqrespobj.frgcurrsinglecheck.detail.RetAtsCJFrgCurrCheckDetail;
import com.fingard.xml.XmlTextWriter;

/**
 * 海外--付款预检响应ATS
 */
public class RetAtsCJFrgCurrCheck extends RetAtsBase {
    public String reqBatchNO;
    public String batRespCode;
    public String batRespInfo;
    public String batTransState;
    public String batPayInfoCode;

    public RetAtsCJFrgCurrCheck(ReqRespHeader p_reqHeader) {
        retHeader = p_reqHeader;
        retXmlWriter = new XmlTextWriter();//用于输出返回ATS的XML报文
    }

    private int writeRdCount = 0;

    public int getWrittenRdCount() {
        return writeRdCount;
    }

    public void writeRetDetail(RetAtsCJFrgCurrCheckDetail p_retDetail) throws Exception {
        if (!hasWrittenBefore) {
            writeBeforeDetail();
        }
        writeRdCount++;
        retXmlWriter.writeStartElement("DetailRecord");
        retXmlWriter.writeElementString("RespCode", p_retDetail.respCode);
        retXmlWriter.writeElementString("RespInfo", p_retDetail.respInfo);
        retXmlWriter.writeElementString("ReqSeqID", p_retDetail.reqSeqID);
        retXmlWriter.writeElementString("TransState", p_retDetail.transState);
        retXmlWriter.writeElementString("PayInfoCode", p_retDetail.payInfoCode);
        retXmlWriter.writeElementString("TransAmt", p_retDetail.transAmt);
        retXmlWriter.writeEndElement();
    }

    private boolean hasWrittenBefore = false;

    public void writeBeforeDetail() throws Exception {
        if (hasWrittenBefore) {
            throw new Exception("writeBeforeDetail已被调用过");
        }
        writeStart();//写返回ATS的统一头部信息
        retXmlWriter.writeElementString("ReqBatchNO", reqBatchNO);
        retXmlWriter.writeElementString("BatRespCode", batRespCode);
        retXmlWriter.writeElementString("BatRespInfo", batRespInfo);
        retXmlWriter.writeElementString("BatTransState", batTransState);
        retXmlWriter.writeElementString("BatPayInfoCode", batPayInfoCode);
        hasWrittenBefore = true;
    }

    public void writeAfterDetail() throws Exception {
        if (!hasWrittenBefore) {
            writeBeforeDetail();
        }
        writeEnd();//写结束
    }
}
